<template>
  <!-- 检查事项 -->
  <div class="dialog-container">
    <el-dialog
      :title="'处理结果回执单'"
      :visible="dialogVisible"
      @open="initData"
      @close="closeDialog"
    >
      <el-form
        ref="form"
        :model="dataForm"
        class="dialog-form"
        :rules="rules"
        label-width="110px"
        size="mini"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="类型" prop="infoType">
              <el-select v-model="dataForm.processingStatus" class="w-100" placeholder="请输入类型">
                <el-option
                  v-for="(item,index) in processingStatus"
                  :key="index+'application_type'"
                  :value="item.value"
                  :label="item.label"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="处理结果" prop="processingResults">
              <el-input v-model="dataForm.processingResults" placeholder="请输入处理结果" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="上传图片：" prop="processingImagePath">
              <UploadImage
                :url="dataForm.processingImagePath"
                @setUrl="setUrl"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button :loading="saveLoading" class="sure-btn" size="mini" type="primary" @click="handleSave">保存</el-button>
        <el-button size="mini" class="cancel-btn" @click="closeDialog">取消</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>
import { upData } from '@/api/business/alarm'
// import { getDict } from '@/utils/dict'
import UploadImage from '@/components/UploadImage/index'

export default {
  name: 'HandleDialog',
  components: {
    UploadImage
  },
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    obj: {
      type: Object,
      default: null
    }
  },
  data() {
    return {
      saveLoading: false,
      dataForm: {
        id: null,
        processingStatus: 'e003_04',
        processingResults: null,
        processingImagePath: ''
      },
      processingStatus: [
        { value: 'e003_04', label: '处理' },
        { value: 'e003_03', label: '回退' }
      ],
      rules: {
        processingStatus: [{ required: true, message: '请选择处理类型', trigger: 'change' }]
      }
    }
  },
  created() {

  },
  methods: {
    initData() {
      this.$nextTick(() => {
        this.$refs['form'].clearValidate()
      })
    },
    handleSave() {
      this.dataForm.id = this.obj.id
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.saveLoading = true
          upData(this.dataForm).then(() => {
            this.$message.success('成功')
            this.$emit('flushPage')
            this.$emit('closeDialog')
            this.clearData()
            this.saveLoading = false
          }).catch(() => {
            this.saveLoading = false
          })
        }
      })
    },
    closeDialog() {
      this.$emit('closeDialog')
      this.clearData()
      this.$refs['form'].clearValidate()
    },
    clearData() {
      this.dataForm = {
        id: null,
        processingStatus: 'e003_04',
        processingResults: null,
        processingImagePath: ''
      }
    },
    setUrl(url) {
      this.dataForm.processingImagePath = url
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
